package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/16 19:30
 * @version  V1.0
 * @description:
 *
 */
func main() {
	var score [3][5]int

	//遍历输入分数
	for i, v := range score {
		for j, _ := range v {
			fmt.Printf("请输入%v班 %v号同学的成绩:", i, j)
			fmt.Scanln(&score[i][j])
		}
		fmt.Println()
	}

	PrintMultiArr(score)

	totalScore := 0
	for i, _ := range score {
		sumForClass := CalSumForClass(score[i])
		totalScore += sumForClass
		fmt.Printf("%v班级 平均分=%v\t", i, CalAvg(sumForClass, len(score[i])))
		fmt.Println()
	}
	fmt.Printf("所有班级人均平均分=%v", CalAvg(totalScore, CalMultiArrEle(score)))
}

func PrintMultiArr(score [3][5]int) {
	for i, v1 := range score {
		for j, v2 := range v1 {
			fmt.Printf("score[%v][%v]=%v\t", i, j, v2)
		}
		fmt.Println()
	}
}

func CalSumForClass(class [5]int) int {
	sum := 0
	for i := range class {
		sum += class[i]
	}
	return sum
}

func CalAvg(sum int, stuNum int) float64 {
	return float64(sum) / float64(stuNum)
}

func CalMultiArrEle(arr [3][5]int) int {
	nums := 0
	for i := range arr {
		nums += len(arr[i])
	}
	return nums
}
